package com.bmf.module.examination.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bmf.constant.AdminResultEnum;
import com.bmf.module.examination.entity.ExaminationType;
import com.bmf.module.examination.service.ExaminationTypeService;
import com.bmf.module.examination.vo.ExaminationTypeCreateVo;
import com.bmf.module.examination.vo.ExaminationTypeResultVo;
import com.bmf.module.examination.vo.ExaminationTypeUpdateVo;
import com.bmf.module.testQuestions.entity.QuestionType;
import com.bmf.module.testQuestions.vo.QuestionTypeCreateVo;
import com.bmf.module.testQuestions.vo.TypeResultVo;
import com.bmf.module.testQuestions.vo.TypeUpdateVo;
import com.bmf.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import com.bmf.core.result.R;

/**
 * (ExaminationType)表控制层
 *
 * @author makejava
 * @since 2022-11-29 17:54:33
 */
@RestController
@RequestMapping("examinationType")
@Api(tags = {"考试分类接口"})
public class ExaminationTypeController{
    /**
     * 服务对象
     */
    @Autowired
    private ExaminationTypeService examinationTypeService;

    /**
     * 查询
     *
     * @return 所有数据
     */
    @GetMapping
    @ApiOperation(value = "查询分类")
    public R<List<ExaminationTypeResultVo>> selectAll() {
        return R.success(examinationTypeService.selectAll());
    }

    /**
     * 新增分类
     *
     * @param examinationTypeCreateVo 实体对象
     * @return 新增结果
     */
    @PostMapping
    @ApiOperation(value = "新增分类")
    public R<Integer> insert(@RequestBody ExaminationTypeCreateVo examinationTypeCreateVo) {
        return R.success(examinationTypeService.insert(examinationTypeCreateVo));
    }

    /**
     * 修改分类
     *
     * @param examinationTypeUpdateVo 实体对象
     * @return 修改结果
     */
    @PutMapping
    @ApiOperation(value = "修改分类")
    public R update(@RequestBody ExaminationTypeUpdateVo examinationTypeUpdateVo) {
        boolean b = examinationTypeService.updateById(BeanCopyUtils.copyBean(examinationTypeUpdateVo, ExaminationType.class));
        AdminResultEnum.UPDATE_EXCEPTION.assertIsTrue(b);
        return R.ok();
    }

    /**
     * 删除分类
     *
     * @return 删除结果
     */
    @GetMapping("/delete/{id}")
    @ApiOperation(value = "删除分类")
    public R<Void> delete(@PathVariable("id") Integer id) {
        boolean b = examinationTypeService.removeById(id);
        AdminResultEnum.DELETE_EXCEPTION.assertIsTrue(b);
        return R.ok();
    }
}

